import React from 'react';
import {AsyncStorage} from 'react-native';
import Utils from './index';
const baseApiUrl = "https://api.studin.com.cn/studin";



/**
 * api请求
 */
export default async (options)=>{

    const userInfo = await Utils.getLoginInfo();
    const data = {
        headers:{
            'Accept': 'application/json',
            'Content-Type': 'application/json',
            'SiLoginToken':userInfo?userInfo["accessToken"]:""
        },
        body:JSON.stringify(options.body),
        method:options.method
    }
    const url = baseApiUrl+options.url;
    console.log(`request:: {url:${url}}  options::`,data);
    let startTime = new Date().getTime();
    return fetch(url,data).then(data=>{
        let endTime = new Date().getTime();
        console.log("url:",options.url," data ::",data);
        console.log("time::",(endTime - startTime), " ms ");
        return data.json();
    });
}


